/**
 *
 */
package com.starmark.core.framework.exception;

import com.starmark.core.framework.response.IHttpCode;
import com.starmark.core.framework.response.HttpCode;
import org.apache.commons.lang3.StringUtils;
import org.springframework.ui.ModelMap;

import java.time.Instant;


/**
 * @author starmark
 * @version 2018年6月7日 下午8:43:02
 */
@SuppressWarnings("serial")
public class BaseException extends RuntimeException {
    public BaseException() {
    }

    public BaseException(Throwable ex) {
        super(ex);
    }

    public BaseException(String message) {
        super(message);
    }

    public BaseException(String message, Throwable ex) {
        super(message, ex);
    }

    public void handler(ModelMap modelMap) {
        modelMap.put("code", getCode().code());
        if (StringUtils.isNotBlank(getMessage())) {
            modelMap.put("msg", getMessage());
        } else {
            modelMap.put("msg", getCode().msg());
        }
        modelMap.put("timestamp",Instant.now().toEpochMilli());
    }

    public IHttpCode getCode() {
        return HttpCode.INTERNAL_SERVER_ERROR;
    }
}
